package com.boonya.spring.controller;

import com.alibaba.fastjson.JSONObject;
import com.boonya.spring.beans.DataConstruct;
import com.boonya.spring.beans.Order;
import com.boonya.spring.beans.Product;
import com.boonya.spring.beans.Property;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: TestController
 * @Description: TODO(功能说明 : 测试相关数据注入)
 * @author: pengjunlin
 * @motto: 学习需要毅力，那就秀毅力
 * @date 2021/3/28 9:22
 */
@RestController
public class TestController {

    @Autowired
    Product product;

    @Autowired
    Order order;

    @Autowired
    DataConstruct dataConstruct;

    @Autowired
    Property property;

    @RequestMapping("getProduct.do")
    @ResponseBody
    public String getProduct() {
        Product mocked = Mockito.mock(Product.class);
        Map map = new HashMap();
        map.put("autowired", product);
        map.put("mocked", mocked);
        return JSONObject.toJSONString(map);
    }

    @RequestMapping("getOrder.do")
    public Order getOrder() {
        return order;
    }

    @RequestMapping("getDataConstruct.do")
    public DataConstruct getDataConstruct() {
        return dataConstruct;
    }

    @RequestMapping("getProperty.do")
    public Property getProperty() {
        return property;
    }

    @RequestMapping("getProductByDateEditor.do")
    public String getProductByDateEditor() {
        order.getProduct().setProductDate(new Date());
        return order.getProduct().getProductDate().toLocaleString();
    }
}
